#include <iostream>
using namespace std;

int main(){
	freopen("in.txt","r",stdin);
	int n;
	cin >> n;
	int a[n];
	for(int i=0; i<n; i++) cin >> a[i];
	int i,j,sum = 0,max_sum = -1,front,rear,flag = 0;
	for(i=0,j=0; j<n; j++){
		if( a[j]>=0 ) flag = 1;
		if( (sum += a[j])<0 ){
			i = j + 1;
			sum = 0;
		}else if( sum>max_sum ){
			front = i;
			rear = j;
			max_sum = sum;
		}
	}
	if( flag==0 ){
		front = 0;
		rear = n - 1;
		max_sum = 0;
	}
	cout << max_sum << " " << a[front] << " " << a[rear];
	return 0;
}
